package com.example.demo.producer;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Song Yinghui
 * @date 2019/12/6
 * @Version 1.0
 */

@Component
public class ProduceTest {

    @Autowired
    private AmqpTemplate amqpTemplate ;

    int count  = 0 ;
    String msg = "你好呀,这是第一次学习RabbitMQ:"+new Date().getTime();


    public void send(){
//        amqpTemplate.convertAndSend("exchange", "topic.message", msg);
        amqpTemplate.send(new Message(msg.getBytes(),new MessageProperties()));
        System.out.println("msg send success ---");
    }

    public void sendQueue(){
        count++;
        amqpTemplate.convertAndSend("firstQueue",msg+count);
    }

    public void sendQueue1(){
        amqpTemplate.convertAndSend("firstQueue1","这是queue1发出的消息："+count);
    }

}
